package main

import (
	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/app"
	"fyne.io/fyne/v2/driver/desktop"
	"fyne.io/fyne/v2/widget"
	"log"
)

func main() {
	a := app.New()
	r, _ := fyne.LoadResourceFromPath("img/logo.ico")
	a.SetIcon(r)

	// 托盘菜单
	makeTray(a)

	//a.SetIcon(theme.FyneLogo())
	w := a.NewWindow("Hello World")
	w.SetContent(widget.NewLabel("Hello World!"))

	w.Resize(fyne.NewSize(500, 320))
	w.SetMaster()
	w.ShowAndRun()
}

func makeTray(a fyne.App) {
	if desk, ok := a.(desktop.App); ok {
		h := fyne.NewMenuItem("你好啊", func() {})
		menu := fyne.NewMenu("Hello World", h)
		h.Action = func() {
			log.Println("System tray menu tapped")
			h.Label = "Welcome"
			menu.Refresh()
		}
		desk.SetSystemTrayMenu(menu)
	}
}
